package com.duowei.diandan.db;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;

import com.duowei.diandan.BuildConfig;
import com.duowei.diandan.app.App;
import com.duowei.diandan.db.converter.Converters;
import com.duowei.diandan.db.dao.AuthDao;
import com.duowei.diandan.db.dao.CxdmxxxDao;
import com.duowei.diandan.db.dao.DcczDao;
import com.duowei.diandan.db.dao.DmjyxmsslbDao;
import com.duowei.diandan.db.dao.DmkwdydpDao;
import com.duowei.diandan.db.dao.DmpzsdDao;
import com.duowei.diandan.db.dao.DpzszDao;
import com.duowei.diandan.db.dao.FxhykszDao;
import com.duowei.diandan.db.dao.GklxDao;
import com.duowei.diandan.db.dao.JgszDao;
import com.duowei.diandan.db.dao.JycsszDao;
import com.duowei.diandan.db.dao.JyxmszDao;
import com.duowei.diandan.db.dao.MzszjbxxDao;
import com.duowei.diandan.db.dao.MzszmxxxDao;
import com.duowei.diandan.db.dao.PaySetDao;
import com.duowei.diandan.db.dao.RollMessageDao;
import com.duowei.diandan.db.dao.TcmcDao;
import com.duowei.diandan.db.dao.TcsdDao;
import com.duowei.diandan.db.dao.WmlsbDao;
import com.duowei.diandan.db.dao.WmlsbjbDao;
import com.duowei.diandan.db.dao.WxfwqdzDao;
import com.duowei.diandan.db.dao.YhjbqkDao;
import com.duowei.diandan.db.entry.Auth;
import com.duowei.diandan.db.entry.Cxdmxxx;
import com.duowei.diandan.db.entry.Dccz;
import com.duowei.diandan.db.entry.Dmjyxmsslb;
import com.duowei.diandan.db.entry.Dmkwdydp;
import com.duowei.diandan.db.entry.Dmpzsd;
import com.duowei.diandan.db.entry.Dpzsz;
import com.duowei.diandan.db.entry.Fxhyksz;
import com.duowei.diandan.db.entry.Gklx;
import com.duowei.diandan.db.entry.Jgsz;
import com.duowei.diandan.db.entry.Jycssz;
import com.duowei.diandan.db.entry.Jyxmsz;
import com.duowei.diandan.db.entry.Mzszjbxx;
import com.duowei.diandan.db.entry.Mzszmxxx;
import com.duowei.diandan.db.entry.PaySet;
import com.duowei.diandan.db.entry.RollMessage;
import com.duowei.diandan.db.entry.Tcmc;
import com.duowei.diandan.db.entry.Tcsd;
import com.duowei.diandan.db.entry.Wmlsb;
import com.duowei.diandan.db.entry.Wmlsbjb;
import com.duowei.diandan.db.entry.Wxfwqdz;
import com.duowei.diandan.db.entry.Yhjbqk;

@Database(entities = {Dmjyxmsslb.class, Jyxmsz.class, Tcmc.class, Tcsd.class, Dpzsz.class,
        Dmpzsd.class, Dmkwdydp.class, Yhjbqk.class, Wmlsbjb.class, Wmlsb.class, Fxhyksz.class,
        Wxfwqdz.class, Jgsz.class, Cxdmxxx.class, Mzszjbxx.class, Mzszmxxx.class, Jycssz.class,
        Gklx.class, PaySet.class, RollMessage.class, Dccz.class, Auth.class},
        version = 112, exportSchema = false)
@TypeConverters(value = {Converters.class})
public abstract class AppDatabase extends RoomDatabase {

    public abstract DmjyxmsslbDao dmjyxmsslbDao();

    public abstract JyxmszDao jyxmszDao();

    public abstract TcmcDao tcmcDao();

    public abstract TcsdDao tcsdDao();

    public abstract DpzszDao dpzszDao();

    public abstract DmpzsdDao dmpzsdDao();

    public abstract DmkwdydpDao dmkwdydpDao();

    public abstract YhjbqkDao yhjbqkDao();

    public abstract WmlsbjbDao wmlsbjbDao();

    public abstract WmlsbDao wmlsbDao();

    public abstract FxhykszDao fxhykszDao();

    public abstract WxfwqdzDao wxfwqdzDao();

    public abstract JgszDao jgszDao();

    public abstract CxdmxxxDao cxdmxxxDao();

    public abstract MzszjbxxDao mzszjbxxDao();

    public abstract MzszmxxxDao mzszmxxxDao();

    public abstract JycsszDao jycsszDao();

    public abstract GklxDao gklxDao();

    public abstract PaySetDao paySetDao();

    public abstract RollMessageDao rollMessageDao();

    public abstract DcczDao dcczDao();

    public abstract AuthDao authDao();

    private static AppDatabase INSTANCE;

    public static AppDatabase getDatabase() {
        // TODO: 2018-03-01 数据库设置
        if (BuildConfig.DEBUG) {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(App.getApp(), AppDatabase.class, "data.db")
                        .allowMainThreadQueries()
                        .fallbackToDestructiveMigration()
                        .build();
            }

        } else {
            if (INSTANCE == null) {
                INSTANCE = Room.inMemoryDatabaseBuilder(App.getApp(), AppDatabase.class)
                        .allowMainThreadQueries()
                        .build();
            }
        }

//        if (INSTANCE == null) {
//            INSTANCE = Room.inMemoryDatabaseBuilder(App.getApp(), AppDatabase.class)
//                    .allowMainThreadQueries()
//                    .build();
//        }

        return INSTANCE;
    }
}
